package com.hxzy.servlet.UmsMemberTask;

import com.hxzy.entity.UmsMemberTask;
import com.hxzy.service.UmsMemberTaskService;
import com.hxzy.service.impl.UmsMemberTaskServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/UmsMemberTask/insert")
public class insert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/UmsMemberTask/insert.jsp").forward(req,res);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        res.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");

        UmsMemberTask task=new UmsMemberTask();

        String name=req.getParameter("name");
        task.setName(name);

        /**
         * 赠送成长值
         */
        Integer growth=Integer.parseInt(req.getParameter("growth"));
        task.setGrowth(growth);

        /**
         * 赠送积分
         */
        Integer intergration=Integer.parseInt(req.getParameter("intergration"));
        task.setIntergration(intergration);

        /**
         * 任务类型：0->新手任务；1->日常任务
         */
        Integer type=Integer.parseInt(req.getParameter("type"));
        task.setType(type);

        UmsMemberTaskService service=new UmsMemberTaskServiceImpl();
        boolean insert = service.insert(task);

        PrintWriter out=res.getWriter();
        out.println( insert? "新增成功": "新增失败");
        //输出刷新
        out.flush();
        out.close();
    }
}
